const express = require('express');
const router = express.Router();
const request = require('request');

router.post('/handleFontFamily', (req, res, next) => {
	// 调用有字库第三方的接口
	const {ApiKey, AccessKey, Content} = req.body;
	const url = `http://service.youziku.com/webFont/getFontFace`;
	const params = {ApiKey, AccessKey, Content}
	request.post({url, form: params}, (err, response, body)=>{
		if(err){
			throw err;
		}
		console.log(body);
		res.send(body);
	});

	// // 发送模板消息的逻辑，先获取全局的access_token，然后调用微信发送模板信息的接口
	// const appid = 'wx06c0a14577c208b3';
	// const appsecret = 'c70fb7407b2f010933715a92837446e5';
	// let tokenUrl = `https://api.weixin.qq.com/cgi-bin/token`;
	// tokenUrl += `?grant_type=client_credential&appid=${appid}&secret=${appsecret}`;
	// request(tokenUrl, function(error, response, body) {
	// 	if (error) {
	// 		throw error;
	// 	}
	// 	const result = JSON.parse(body);
	// 	const { access_token } = result;
	// 	const openid = "oR10X1JQbxfR0Hf2DqFxrq6bQgBw";
	// 	const params = {
	// 		"touser": openid,
	// 		"template_id": "q68kcHXtR33Gy_iq58l7sod19LWLYUKBIy34yBJDe5Q",
	// 		"url": `http://vhjmlw.free.ngrok.cc/#/App/OrderInfo?openid=${openid}`,
	// 		"data": {
	// 			"name": {
	// 				"value": "张建磊",
	// 				"color": "#173177"
	// 			},
	// 			"company": {
	// 				"value": "众创空间",
	// 				"color": "#173177"
	// 			},
	// 			"address": {
	// 				"value": "不能说啊",
	// 				"color": "#173177"
	// 			}
	// 		}
	// 	}
	// 	let url = `https://api.weixin.qq.com/cgi-bin/message/template/send`;
	// 	url += `?access_token=${access_token}`;
	// 	request({
	// 		method: 'POST',
	// 		uri: url,
	// 		json: true,
	// 		body: params,
	// 	}, function(error, response, body){
	// 		if(error){
	// 			throw error;
	// 		}
	// 		res.send(body);
	// 	});
	// });


});

module.exports = router;